package twoD.Csg.tests;

import inf.swing.IcebSwingUtils;
import inf.v3d.obj.Object3D;
import inf.v3d.view.Viewer;
import twoD.Csg.Circle;
import twoD.Csg.CsgNode;
import twoD.Csg.CsgNode.Operation;
import twoD.Csg.IPrimitive;
import twoD.Csg.QuadTree;
import twoD.Csg.Rectangle;
import twoD.Csg.Rotation;
import twoD.Csg.Transformation;
import twoD.Csg.Translation;

public class QuadTreeDemo {

	public void testDraw1() {
		IPrimitive R = new Rectangle(-1, -1, 2, 2);
		IPrimitive C = new Circle(1, 0, 1);

		CsgNode n1 = new CsgNode();
		n1.setPrimitive(R);
		CsgNode n2 = new CsgNode();
		n2.setPrimitive(C);
		CsgNode n = new CsgNode();

		n.setOperation(Operation.UNION, n1, n2);

		IPrimitive C1 = new Circle(-1, 0, 1);
		CsgNode n3 = new CsgNode();
		n3.setPrimitive(C1);

		CsgNode nr = new CsgNode();
		nr.setOperation(Operation.UNION, n, n3);

		QuadTree T = new QuadTree(nr, -2, -2, 4, 4);
		Viewer v = new Viewer();
		T.draw(true, Object3D.CM_UNI, v);
		v.setVisible(true);
	}

	public void testDraw2() {
		IPrimitive R = new Rectangle(-2, 0, 2, 2);
		IPrimitive C = new Circle(0, 0, 0.5);

		CsgNode n1 = new CsgNode();
		n1.setPrimitive(R);
		CsgNode n2 = new CsgNode();
		n2.setPrimitive(C);
		CsgNode n = new CsgNode();

		n.setOperation(Operation.DIFFERENCE, n1, n2);

		QuadTree T = new QuadTree(n, -2, 0, 2, 6);
		Viewer v = new Viewer();
		T.draw(true, Object3D.CM_UNI, v);
		v.setVisible(true);
	}

	public void testDraw3() {
		double l = 42;
		double h = 18;
		double c = 5;
		double t = 2;

		IPrimitive R1 = new Rectangle(0, 0, l, h);
		IPrimitive R2 = new Rectangle((l - t) / 2, 0, t, c);

		CsgNode n1 = new CsgNode();
		CsgNode n2 = new CsgNode();
		CsgNode n = new CsgNode();

		n1.setPrimitive(R1);
		n2.setPrimitive(R2);
		n.setOperation(Operation.DIFFERENCE, n1, n2);
		n.setSamplingRate(8);

		QuadTree T = new QuadTree(n, -0.5, -0.5, l + 1, 6);
		Viewer v = new Viewer();
		T.draw(true, Object3D.CM_UNI, v);
		v.setVisible(true);
	}

	public void testDraw4() {
		double r = 100;

		IPrimitive C1 = new Circle(0, 0, r);
		IPrimitive C2 = new Circle(0, 0, r / 2);

		CsgNode n1 = new CsgNode();
		CsgNode n2 = new CsgNode();
		n1.setPrimitive(C1);
		n2.setPrimitive(C2);

		Transformation T = new Translation(r / 4, 0);
		T = T.multiply(new Rotation(0, 0, Math.PI / 2));
		C2.setTransformation(T);

		IPrimitive R = new Rectangle(-r, -r, 2 * r, r);
		CsgNode n3 = new CsgNode();
		n3.setPrimitive(R);
		CsgNode n4 = new CsgNode();
		n4.setOperation(Operation.UNION, n1, n3);

		CsgNode n5 = new CsgNode();
		n5.setOperation(Operation.DIFFERENCE, n4, n2);

		QuadTree Q = new QuadTree(n5, -r - 0.5, -r - 0.5, 2 * r + 1, 6);
		Viewer v = new Viewer();
		Q.draw(true, Object3D.CM_UNI, v);
		v.setVisible(true);
	}

	public static void main(String[] args) {
		new QuadTreeDemo().testDraw4();
	}

}
